<template>
	<view>
		<view class="uni-container">
			<uni-table ref="table" border stripe emptyText="暂无更多数据">
				<uni-tr>
					<!-- <uni-th width="100" align="center">code</uni-th> -->
					<uni-th width="150" align="center">note</uni-th>
					<uni-th align="center">name</uni-th>
					<uni-th width="100" align="center"></uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<!-- <uni-td>{{ item.code }}</uni-td> -->
					<uni-td>
						<view class="name">{{ item.note }}</view>
					</uni-td>
					<uni-td align="center">
					    <input type="text" v-model="item.name" ></input>
					</uni-td>
					<uni-td>
						<view class="uni-group">
							<button class="uni-button" size="mini" type="warn" @click="edit(item)">修改</button>
						</view>
					</uni-td>
				</uni-tr>
			</uni-table>
		</view>
	</view>
</template>

<script>
import request from "../../untils/request.js";
export default {
	data() {
		return {
			tableData: [],
		}
	},
	onLoad() {
		uni.startPullDownRefresh();
	},
	onPullDownRefresh() {
	    this.getData();
	},
	methods: {
		// 获取数据
		getData() {
			request.postMember('/user/info/getDefaultConfig', {
			}).then(res => {
			    if (res.code == '200') {
					console.log(res.data)
			        this.tableData = res.data.dataDictionaries;
					uni.stopPullDownRefresh();
			    }else{
					uni.stopPullDownRefresh();
				}
			})
		},
		//修改
		edit(item) {
			uni.showLoading({
				title:"修改中...",
			    mask: true
			});
			request.postMember('/user/info/changeDefaultConfig', {
				code: item.code,
				name: item.name
			}).then(res => {
			    if (res.code == '200') {
			        this.tableData = res.data.dataDictionaries;
					uni.hideLoading();
					uni.showToast({title: '修改成功',icon:'none',duration: 1000})
			    }else{
					uni.hideLoading();
					uni.showToast({title: '修改失败',icon:'none',duration: 1000})
				}
			})
		}
	}
}
</script>

<style>
/* #ifndef H5 */
page {
	padding-top: 85px;
}
/* #endif */
.uni-group {
	display: flex;
	align-items: center;
}
</style>
